package com.sia.springcloud.protocol.model;

import com.sia.springcloud.model.Device;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @Author: Sirius
 * @Date: 2021/10/3 20:16
 * @Description: 111
 **/
@Slf4j
@Data
public class ModbusDevice implements Serializable {
    private Integer id;
    private Integer collect;
    private String microservice;
    private String protocolName;
    private String deviceName;
    private String description;
    private String host;
    private Integer port;
    private Integer timeout;
    private Integer connectionLimit;
    private static final long serialVersionUID = 1L;

    /**
     * 将Modbus设备对象转换成Protocol设备对象
     *
     * @param modbusDevice
     * @return
     */
    public static Device convert(ModbusDevice modbusDevice) {
        Device device = new Device();
        device.setId(modbusDevice.getId());
        device.setCollect(modbusDevice.getCollect());
        device.setMicroservice(modbusDevice.getMicroservice());
        device.setProtocolName(modbusDevice.getProtocolName());
        device.setDeviceName(modbusDevice.getDeviceName());
        device.setDescription(modbusDevice.getDescription());
        device.setHost(modbusDevice.getHost());
        device.setPort(modbusDevice.getPort());
        device.setTimeout(modbusDevice.getTimeout());
        device.setConnectionLimit(modbusDevice.getConnectionLimit());

        return device;
    }

    /**
     * 将Protocol设备对象转换成Modbus设备对象
     *
     * @param device
     * @return
     */
    public static ModbusDevice reconvert(Device device) {

        ModbusDevice modbusDevice = new ModbusDevice();

        modbusDevice.setId(device.getId());
        modbusDevice.setCollect(device.getCollect());
        modbusDevice.setMicroservice(device.getMicroservice());
        modbusDevice.setProtocolName(device.getProtocolName());
        modbusDevice.setDeviceName(device.getDeviceName());
        modbusDevice.setDescription(device.getDescription());
        modbusDevice.setHost(device.getHost());
        modbusDevice.setPort(device.getPort());
        modbusDevice.setTimeout(device.getTimeout());
        modbusDevice.setConnectionLimit(device.getConnectionLimit());

        return modbusDevice;
    }
}
